package kunsch.bdd;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractNode
{

	private AbstractNode oneChild;
	private AbstractNode zeroChild;
	private AbstractNode parent;

	private String description;


	public AbstractNode(String description)
	{
		this.description = description;

	}

	public AbstractNode getOneChild()
	{
		return oneChild;
	}

	protected void setOneChild(AbstractNode oneChild)
	{
		this.oneChild = oneChild;
		if (oneChild != null)
			oneChild.setParent(this);
	}

	public AbstractNode getZeroChild()
	{
		return zeroChild;
	}

	protected void setZeroChild(AbstractNode zeroChild)
	{
		this.zeroChild = zeroChild;
		if (zeroChild != null)
			zeroChild.setParent(this);
	}

	public String getDescription()
	{
		return description;
	}

	protected void setDescription(String description)
	{
		this.description = description;
	}

	public boolean equalTo(Object object)
	{

		if (!(object instanceof AbstractNode))
		{
			return false;
		}

		AbstractNode abstractNode = (AbstractNode) object;

		if (this.description != abstractNode.description)
		{
			return false;
		}

		if (this.getZeroChild() == null && abstractNode.getZeroChild() != null)
		{
			return false;
		}

		if (this.getZeroChild() != null && !this.getZeroChild().equalTo(abstractNode.getZeroChild()))
		{
			return false;
		}

		if (this.getOneChild() == null && abstractNode.getOneChild() != null)
		{
			return false;
		}

		if (this.getOneChild() != null && !this.getOneChild().equalTo(abstractNode.getOneChild()))
		{
			return false;
		}

		return true;

	}

	@Override
	public String toString()
	{
		return description;
	}

	public AbstractNode getParent()
	{
		return parent;
	}

	public void setParent(AbstractNode parent)
	{
		this.parent = parent;
	}


}
